package com.epsoft.odin7cj.flow.api.define;

import java.util.ArrayList;
import java.util.List;

//import org.activiti.engine.RepositoryService;
//import org.activiti.engine.repository.ProcessDefinition;
//import org.activiti.engine.repository.ProcessDefinitionQuery;

import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.repository.ProcessDefinitionQuery;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.epsoft.odin7cj.core.dto.RetData;
import com.epsoft.odin7cj.flow.model.define.BizFlowDefinition;

/**
 * DESC: 流程定义控制类
 * @author 胡义振  
 * @date 2019年12月16日
 */
@RestController
@RequestMapping("/api/flow/define")
public class DefinitionApi {

	@Autowired
	private RepositoryService repositoryService;
	
    /**
     * DESC: 获取所有流程定义
     * @return
     * @throws Exception
     */
	@RequestMapping("/getAll")
    public RetData<List<BizFlowDefinition>> getAllAuditFlowDef() throws Exception {
    	RetData<List<BizFlowDefinition>> retData = new RetData<List<BizFlowDefinition>>();
    	List<ProcessDefinition> listFlowDef = new ArrayList<ProcessDefinition>();
    	ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
    	
		if(processDefinitionQuery!=null) {
			listFlowDef = processDefinitionQuery.list();
		}
		
		List<BizFlowDefinition> listAuditFlowDef = new ArrayList<BizFlowDefinition>();
		for(ProcessDefinition flowDef : listFlowDef) {
			BizFlowDefinition auditFlowDef = new BizFlowDefinition();
			auditFlowDef.setFdId(flowDef.getId());
			auditFlowDef.setFdName(flowDef.getName());
			auditFlowDef.setFdKey(flowDef.getKey());
			auditFlowDef.setDeploymentId(flowDef.getDeploymentId());
			listAuditFlowDef.add(auditFlowDef);
		}
    	retData.setRetBody(listAuditFlowDef);
    	return retData;
    }
	
}
 